<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <com1 :parentmsg="msg" @func="getMsgFromSon"></com1>
    </div>
    <template id="tmpl">
        <div>
            <h1>这是子元素 --- {{parentmsg}}</h1>
            <input type="button" value="向父组件传值" @click="sendMsg">
        </div>
    </template>
    <script>
        var com1 = {
            template: '#tmpl',
            data() {
                return {
                    msg: '这是子组件中的数据',
                    msgFronSon: ''
                }
            },
            methods:{
                sendMsg(){
                    this.$emit('func',this.msg)
                }
            },
            props: ['parentmsg']
        }
        var vm = new Vue({
            el: '#app',
            data: {
                msg: '这是父组件中的数据'
            },
            methods: {
                getMsgFromSon(data) {
                    this.msgFronSon = data
                    console.log(this.msgFronSon)
                }
            },
            components: {
                com1
            }
        });
    </script>
</body>

</html>